#pragma once

#include"../net/campus_whole_server.h"
#include"../sql/campus_sql_connector.h"

class CampusPersonInfoManager
{
public:
    CampusPersonInfoManager(CampusWholeServer* whole_server, CampusSqlConnector* sql_connector);
    ~CampusPersonInfoManager();

    //-----------------网络回调-----------------
    void handlePersonInfo(websocketpp::connection_hdl hdl,json const JMsg);
    void handlePersonInfoModify(websocketpp::connection_hdl hdl,json const JMsg);

    //-----------------数据库回调-----------------
    void onSelectSucess(std::vector<std::vector<std::pair<std::string, std::string>>>& result,CampusSqlInfo* userData);
    void onSelectFail(CampusSqlInfo* userData);

    void onUpdateSucess(CampusSqlInfo* userData);
    void onUpdateFail(CampusSqlInfo* userData);
    
    void onInsertSucess(CampusSqlInfo* userData);
    void onInsertFail(CampusSqlInfo* userData);
    
private:
    void handlePersonInfoSelect(websocketpp::connection_hdl hdl, std::vector<std::vector<std::pair<std::string, std::string>>>& result);
    void handlePersonInfoModifySelect(CampusSqlInfo* userData, std::vector<std::vector<std::pair<std::string, std::string>>>& result);

    void doPersonInfo(websocketpp::connection_hdl hdl, std::string const& uid);
    void doPersonInfoModify(websocketpp::connection_hdl hdl, std::vector<std::pair<std::string,std::string>>& columns);

    void doPersonInfoUpdated(websocketpp::connection_hdl hdl);
    void doPersonInfoInserted(CampusSqlInfo* userData);

    void doInsertPersonInfo(CampusSqlInfo* userData);
    void doUpdatePersonInfo(CampusSqlInfo* userData);

    void printPersonInfo(CampusPersonInfo* p_info);

private:
    CampusWholeServer* whole_server_ = nullptr;
    CampusSqlConnector* sql_connector_ = nullptr;
};